var t = getApp();

Page({
    data: {
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        value_s: "",
        goods_list: [],
        category_id: "",
        catory: [],
        producer_id: "",
        tapStart: !1,
        show: !1,
        list: [ "全部", "蛋白质", "排毒养颜", "茶饮", "全部", "蛋白质", "排毒养颜", "茶饮" ],
        ind: 0,
        showCard: !1
    },
    onLoad: function(t) {
        this.setData({
            producer_id: t.producer_id
        });
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        }), this.getData(), this.onSearch(), this.getCatory();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.searchMore();
    },
    onShareAppMessage: function() {},
    getCatory: function() {
        var a = this, e = t.getNetAddresss("plugin.producer.frontend.goodsCategory.getList");
        t._getNetWork({
            url: e,
            data: {
                producer_id: a.data.producer_id
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    catory: e.data
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getData: function() {
        var a = this, e = t.getNetAddresss("plugin.producer.frontend.producer.getProducerCenterById");
        t._getNetWork({
            url: e,
            data: {
                producer_id: a.data.producer_id
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    info: t.data.data.producer
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    open_one: function() {
        this.setData({
            showCard: !0
        });
    },
    open_two: function() {
        this.setData({
            show: !0
        });
    },
    onClickLeft: function() {
        this.setData({
            showCard: !1
        });
    },
    open_three: function() {
        this.setData({
            show: !1
        });
    },
    toGoods: function(t) {
        var a = t.currentTarget.dataset.goodid;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a
        });
    },
    toproclamation: function(t) {
        wx.navigateTo({
            url: "/packageE/managementIndex/proclamation/proclamation?producer_id=" + this.data.producer_id
        });
    },
    changeValue: function(t) {
        this.setData({
            value_s: t.detail.value
        });
    },
    onSearch: function(a) {
        var e = this;
        this.setData({
            page: 1
        });
        var o = this, s = t.getNetAddresss("plugin.producer.frontend.goods.searchGoods");
        t._postNetWork({
            url: s,
            data: {
                page: o.data.page,
                producer_id: o.data.producer_id,
                search: {
                    keyword: o.data.value_s,
                    category: o.data.category_id
                }
            },
            success: function(t) {
                var a = t.data;
                1 == a.result ? (e.setData({
                    isLoadMore: !0,
                    total_page: a.data.last_page,
                    goods_list: a.data.data
                }), console.log(o.data.goods_list), e.data.total_page || e.setData({
                    total_page: 0
                })) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    searchMore: function() {
        var a = this;
        if (this.setData({
            isLoadMore: !1
        }), !(this.data.page >= this.data.total_page)) {
            var e = this.data.page + 1;
            this.setData({
                page: e
            });
            var o = t.getNetAddresss("plugin.producer.frontend.goods.searchGoods");
            t._postNetWork({
                url: o,
                data: {
                    page: that.data.page,
                    producer_id: that.data.producer_id,
                    search: {
                        keyword: that.data.value_s,
                        category: that.data.category_id
                    }
                },
                success: function(t) {
                    var e = t.data;
                    if (1 == e.result) {
                        var o = e.data.data.concat(a.data.goods_list);
                        a.setData({
                            goods_list: o
                        });
                    } else {
                        wx.showToast({
                            title: e.msg,
                            icon: "none"
                        });
                        var s = a.data.page - 1;
                        a.setData({
                            page: s,
                            isLoadMore: !1
                        });
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    changeIndex: function(t) {
        var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.id;
        this.setData({
            ind: a,
            category_id: e
        }), this.setData({
            page: 1,
            show: !1
        }), this.onSearch();
    }
});